﻿using AutoMapper;
using BPMN.Application.Contracts.DTO.Request.UserInfo;
using BPMN.Application.Contracts.DTO.Response;
using BPMN.Application.Contracts.DTO.Response.RolePermission;
using BPMN.Application.Contracts.DTO.Response.UserInfo;
using BPMN.Application.IService;
using BPMN.Domain.Entity.User;
using BPMN.DomianShare;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Configuration.UserSecrets;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Org.BouncyCastle.Asn1.X9;
using Xceed.Wpf.Toolkit;
using Yitter.IdGenerator;

namespace BPMN.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class UserController : ControllerBase
    {
        private readonly IUserAppService AppUser;

        public UserController(IUserAppService AppUser)
        {
            this.AppUser = AppUser;
        }
        /// <summary>
        /// 测试接口GET
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Test()
        {
            int a = 0;
            int b = 0;
            return Ok(a / b);
        }

        /// <summary>
        /// 显示全部
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetUserInfo()
        {
            return Ok(await AppUser.GetUserInfo());
        }
        /// <summary>
        /// 根据Id获取用户信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetUserInfoById(int Id)
        {
            return Ok(await AppUser.GetUserInfoById(Id));
        }
        /// <summary>
        /// 删除功能
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DeleteUserInfo(int Id)
        {
            return Ok(await AppUser.Delete(Id));
        }
        /// <summary>
        ///  用户添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddUserInfo(UserInfoRequestDto entity)
        {
            return Ok(await AppUser.AddUserInfo(entity));
        }
        /// <summary>
        /// 修改功能
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdateUserInfo(UserInfoRequestDto entity)
        {
            return Ok(await AppUser.UpdateUserInfo(entity));
        }
        /// <summary>
        /// 用户删除功能
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DeleleUserInfo(int UserId)
        {
            return Ok(await AppUser.DeleleUserInfo(UserId));

        }
        /// <summary>
        /// 登录功能
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Pwd"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> LoginAction(string UserName, string Pwd)
        {
            return Ok(await AppUser.LoginAction(UserName, Pwd));
        }
        /// <summary>
        /// 菜单列表显示
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> PermissionListShow(int UserId)
        {
            //中午去吃烤肉拌饭15一份好吃实惠
            return Ok(await AppUser.PermissionListShow(UserId));
        }
        [HttpGet]
        public async Task<IActionResult> GetRolePeimiss(int UserId, int? PermId)
        {
            return Ok(await AppUser.GetRolePeimiss(UserId,PermId));
        }

        /// <summary>
        /// Excel导出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task GetExcel()
        {
            var stdList = (await AppUser.GetUserInfo()).Data;
            //string exceiFile = Application.StartupPath + "\\StudentInfo.xls";
            ExcelHelper<UserInfoShowResponseDto>.SaveExcelFile(PathHelper.GetSecretsPathFromSecretsId+ "用户.xls", "Student", stdList);
            //ExcelHelper<UserInfoShowResponseDto>.SaveExcelFile(exceiFile, "Student", stdList);
        }
        private void ExportHelper_ExportResultEvent(bool res)
        {
            Console.Write(res);
        }

    }
}
